package cn.biplam.front.component.view.common;

import cn.biplam.common.client.DataFilter;
import cn.biplam.common.client.Operator;
import cn.biplam.common.opcode.mdManage.TypeCode.DbSourceCode;
import cn.biplam.common.struc.MdStruc;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.common.wrapper.sqlresult.SqlResult;
import cn.biplam.front.component.data.common.SelectComp;
import cn.biplam.front.html.base.HtmlWindow;

/**
 * 数据源下拉列表选择组件
 * @author XiaoRuxing 2009-6-30下午02:26:03
 * @version 1.0
 */
public class DbSourceSelect {

	/**
	 * 获取数据源下拉列表
	 * @param listPageID   页面ID
	 * @param defaultValue 默认值
	 * @param mUser        用户
	 * @param sHomeUrl     应用系统路径
	 * @return
	 * @throws ErrorMessage
	 */
	public static HtmlWindow get(String listPageID,
			String defaultValue,
			UserInfo mUser,
			String sHomeUrl) throws ErrorMessage{
		SqlResult dbsource=Operator.get(DbSourceCode.Select_All, mUser.getUserID(), new DataFilter()).getSelectResult();
		return new SelectComp().get(listPageID,defaultValue,sHomeUrl,dbsource,
				"dsid", "dsname");
	}
	
	/**
	 * 获取数据源下拉列表
	 * @param listPageID   页面ID
	 * @param defaultValue 默认值
	 * @param mUser        用户
	 * @param sHomeUrl     应用系统路径
	 * @param modelType    获取指定模型下的数据源
	 * @return
	 * @throws ErrorMessage
	 */
	public static HtmlWindow get(String listPageID,
			String defaultValue,
			UserInfo mUser,
			String sHomeUrl,
			String modelType) throws ErrorMessage{
		DataFilter filter = new DataFilter();
		filter.put(MdStruc.DbSourStruc.MODEL_TYPE, modelType);
		SqlResult dbsource=Operator.get(DbSourceCode.Select_By_Type, mUser.getUserID(), filter).getSelectResult();
		return new SelectComp().get(listPageID,defaultValue,sHomeUrl,dbsource,
				"dsid", "dsname");
	}
}
